home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15703 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.1 KB  |  84 lines

  1. Path: nntp.teleport.com!usenet
  2. From: GHouck <hksys@teleport.com>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: HELP- PASSING STRUCTURE IN FUNCTION PROTOTYPE?
  5. Date: 21 Apr 1996 07:59:12 GMT
  6. Organization: systems hk
  7. Message-ID: <4lcpsg$9ta@nadine.teleport.com>
  8. References: <31784e1f.4961188@news.planet.net>
  9. NNTP-Posting-Host: ip-pdx14-54.teleport.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.22 (Windows; I; 32bit)
  14.  
  15. cygnusx@planet.net (David) wrote:
  16. [snip]
  17. >When I try to compile I get only one error. It is at the beginning of
  18. >the function prototype  (morethan) and this is the error statment?? .
  19. >                         [  )  expected  ] .
  20. >Is this somthing with the way I wrote the program or just something in
  21. >this line? I am not sure this is a good way to go about this program .
  22. >
  23. >struct employee {
  24. >    char first[10];
  25. >    char last [10];
  26. >    float salary;
  27. >    };
  28. >
  29. >morethan(struct employee,float);
  30. >
  31. >main(){
  32. > int ctr;
  33. > struct employee data[4];
  34. >    for (ctr=0;ctr<4;ctr++)
  35. >       {printf("please enter first name:\n");
  36. [snip]
  37. >   for (ctr=0;ctr<4;ctr++)
  38. >     {printf("%s\n",data[ctr].first);
  39. >     printf("%s\n",data[ctr].last);
  40. >     printf("%f\n",data[ctr].salary);}
  41. >  morethan(data[4],1000);
  42. >  return 0;}
  43. >  morethan (struct employee a[],b)      /*  error is on this line  */
  44. > { for(i=0;i<4;i++)
  45. >       if(data[i].salary > b)
  46. >
  47. >         printf("%s",data[i].first);
  48. >         printf("%s",data[i].last);}
  49.  
  50.  
  51. David,
  52.  
  53. Your function prototype is actually the line just below your
  54. structure declaration.  In it you are stating that the function
  55. accepts a structure 'employee' and a 'float' type; yet, when 
  56. you define your function at the bottom, you specify an 'array
  57. of structs' and have given no type for 'b'.
  58.  
  59. In your prototype, I would suggest:
  60.  
  61.   int morethan( struct employee data[], float limit );
  62.  
  63. Then in your function definition below:
  64.  
  65.   int morethan ( struct employee data[], float b )
  66.   {
  67.     int  i;
  68.  
  69.     for( i=0; i<4; i++ ) {
  70.       if( data[i].first > b ) {
  71.         printf( ...
  72.         printf( ...
  73.       }
  74.     }
  75.   }
  76.  
  77.  
  78.  
  79.  
  80. Yours, Geoff Houck
  81.  
  82.  
  83.  
  84.